Add a test for #2076, preservation of line endings style
authorGleb Kozyrev <gleb@gkoz.com>
Fri, 30 Oct 2015 10:39:35 +0000 (12:39 +0200)
committerGleb Kozyrev <gleb@gkoz.com>
Fri, 30 Oct 2015 11:49:45 +0000 (13:49 +0200)
tests/test_cargo_generate_lockfile.rs

index 276791aa0338702216b385398cece1fbd4e2821f..c8a9bb6a274151312fd709990a906eccec716250 100644 (file)
@@ -2,7 +2,7 @@ use std::fs::File;
 use std::io::prelude::*;
 
 use support::{project, execs};
-use hamcrest::assert_that;
+use hamcrest::{assert_that, existing_file};
 
 fn setup() {}
 
@@ -122,3 +122,52 @@ foo = "bar"
     File::open(&lockfile).unwrap().read_to_string(&mut lock).unwrap();
     assert!(lock.contains(metadata.trim()), "{}", lock);
 });
+
+test!(preserve_line_endings_issue_2076 {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            authors = []
+            version = "0.0.1"
+        "#)
+        .file("src/main.rs", "fn main() {}")
+        .file("bar/Cargo.toml", r#"
+            [package]
+            name = "bar"
+            authors = []
+            version = "0.0.1"
+        "#)
+        .file("bar/src/lib.rs", "");
+
+    let lockfile = p.root().join("Cargo.lock");
+    assert_that(p.cargo_process("generate-lockfile"),
+                execs().with_status(0));
+    assert_that(&lockfile,
+                existing_file());
+    assert_that(p.cargo("generate-lockfile"),
+                execs().with_status(0));
+
+    let mut lock0 = String::new();
+    {
+        File::open(&lockfile).unwrap().read_to_string(&mut lock0).unwrap();
+    }
+
+    assert!(lock0.starts_with("[root]\n"));
+
+    let lock1 = lock0.replace("\n", "\r\n");
+    {
+        File::create(&lockfile).unwrap().write_all(lock1.as_bytes()).unwrap();
+    }
+
+    assert_that(p.cargo("generate-lockfile"),
+                execs().with_status(0));
+
+    let mut lock2 = String::new();
+    {
+        File::open(&lockfile).unwrap().read_to_string(&mut lock2).unwrap();
+    }
+
+    assert!(lock2.starts_with("[root]\r\n"));
+    assert_eq!(lock1, lock2);
+});